#include"comm.hpp"

using namespace std;

int main()
{
    key_t key=creat_key();
    //获取共享内存
    int shmid=shmget(key,4096,IPC_CREAT);
    //关联到进程
    char* str=(char*)shmat(shmid,nullptr,0);
    if(str==(char*)-1)
    {
        log()<<"attach failed"<<endl;
        exit(3);
    }
    log()<<"attach successed"<<endl;

    //使用
    //写入
    while(1)
    {
        cout<<"客户端:输入#:"<<endl;
        ssize_t s = read(0,str,4096);
        if(s>0)
        {
            str[s]='\0';
        }
    }


    //去关联
    shmdt(str);
    log()<<"detach sucess"<<endl;

    return 0;
}